<template>
	<el-card class="layout-query">
		<el-form ref="queryRef" :inline="true" :model="state.queryForm" @keyup.enter="getDataList()">
			<el-form-item prop="sendTime">
				<el-date-picker v-model="state.queryForm.sendTime" type="daterange" range-separator="-"
					start-placeholder="发送时间从" end-placeholder="至" value-format="YYYY-MM-DD HH:mm:ss" />
			</el-form-item>
			<el-form-item>
				<im-group-select v-model="state.queryForm.groupId" placeholder="群组"></im-group-select>
			</el-form-item>
			<el-form-item>
				<im-user-select v-model="state.queryForm.sendId" placeholder="发送用户"></im-user-select>
			</el-form-item>
			<el-form-item>
				<el-input v-model="state.queryForm.content" placeholder="消息内容"></el-input>
			</el-form-item>
			<el-form-item>
				<ma-dict-select v-model="state.queryForm.type" placeholder="消息类型" dict-type="im_message_type" clearable>
				</ma-dict-select>
			</el-form-item>
			<el-form-item>
				<el-button icon="Search" type="primary" @click="getDataList()">查询</el-button>
			</el-form-item>
			<el-form-item>
				<el-button icon="RefreshRight" @click="reset(queryRef)">重置</el-button>
			</el-form-item>
		</el-form>
	</el-card>

	<el-card>
		<el-table v-loading="state.dataListLoading" :data="state.dataList" border class="layout-table">
			<el-table-column prop="groupName" label="群组名" header-align="center" align="center"></el-table-column>
			<el-table-column prop="sendUserName" label="发送用户" header-align="center" align="center"></el-table-column>
			<el-table-column prop="content" label="发送内容" header-align="center" align="center" width="350">
				<template #default="scope">
					<im-message-content :message="scope.row"></im-message-content>
				</template>
			</el-table-column>
			<ma-dict-column prop="type" label="消息类型" dict-type="im_message_type" header-align="center"
				align="center"></ma-dict-column>
			<ma-dict-column prop="status" label="已撤回" dict-type="boolean_type" header-align="center" align="center">
				<template #default="scope">
					<ma-dict-label dict-type="boolean_type" :dict-value="scope.row.status == 2 ? 1 : 0" />
				</template>
			</ma-dict-column>
			<el-table-column prop="sendTime" label="发送时间" header-align="center" align="center"></el-table-column>
			<el-table-column label="操作" fixed="right" header-align="center" align="center" width="150">
				<template #default="scope">
					<el-button v-auth="'im:message:group:info'" type="primary" link
						@click="detailHandle(scope.row.id)">详情</el-button>
				</template>
			</el-table-column>
		</el-table>
		<el-pagination :current-page="state.page" :page-sizes="state.pageSizes" :page-size="state.limit"
			:total="state.total" layout="total, sizes, prev, pager, next, jumper" @size-change="sizeChangeHandle"
			@current-change="currentChangeHandle">
		</el-pagination>

		<!-- 详情 -->
		<detail ref="detailRef" @refreshDataList="getDataList"></detail>
	</el-card>
</template>

<script setup lang="ts" name="ImGroup_messageIndex">
import { useCrud } from '@/hooks'
import { reactive, ref } from 'vue'
import { IHooksOptions } from '@/hooks/interface'
import Detail from './detail.vue'

const state: IHooksOptions = reactive({
	dataListUrl: '/im/message/group/page',
	queryForm: {
	}
})

const queryRef = ref()
const detailRef = ref()
const detailHandle = (id?: number) => {
	detailRef.value.init(id)
}

const { getDataList, sizeChangeHandle, currentChangeHandle, reset } = useCrud(state)
</script>
